﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.GridlistUI.view {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.aswingui.*;

    public class ItemCellView extends JPanel implements IAssetComponent, IContentComponent {

        protected var m_assetDict:Dictionary;
        protected var m_content:DisplayObject;
        protected var m_panel:JPanel;
        protected var m_bodyPanel:JPanel;
        protected var m_footPanel:JPanel;
        protected var m_contentPanel:JPanel;
        protected var m_bodyPanelInsets:Insets;
        protected var m_footPanelInsets:Insets;

        public function ItemCellView(){
            this.m_assetDict = new Dictionary();
            this.m_bodyPanelInsets = new Insets();
            this.m_footPanelInsets = new Insets();
            super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, SoftBoxLayout.CENTER));
            this.m_panel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            this.m_bodyPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            this.m_footPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_contentPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
        }
        public function get bgAsset():DisplayObject{
            return (this.m_assetDict["bg"]);
        }
        public function makeAssets(_arg1:Dictionary):void{
            var _local2:DisplayObject = _arg1[DelayedAssetLoader.MARKET_ASSETS];
            this.m_assetDict["bg"] = (new (_local2["marketItem"])() as DisplayObject);
        }
        public function setContent(_arg1:DisplayObject):void{
            this.m_content = _arg1;
            this.updateContentPanel();
            ASwingHelper.prepare(this);
        }
        public function updateView(_arg1):void{
        }
        final public function build():void{
            this.cleanup();
            this.initLayout();
            this.addEventListeners();
            ASwingHelper.prepare(this);
        }
        public function cleanup():void{
            this.removeAll();
            this.removeEventListeners();
        }
        protected function initLayout():void{
            if (this.m_panel){
                if (this.m_bodyPanel){
                    this.updateBodyPanel();
                    if (this.m_contentPanel){
                        this.updateContentPanel();
                        this.m_bodyPanel.append(this.m_contentPanel);
                    };
                    this.m_panel.append(this.m_bodyPanel);
                };
                if (this.m_footPanel){
                    this.updateFooterPanel();
                    this.m_panel.append(this.m_footPanel);
                };
                this.append(this.m_panel);
            };
        }
        protected function updateBodyPanel():void{
            if (this.bgAsset){
                ASwingHelper.setSizedBackground(this.m_bodyPanel, this.bgAsset, this.m_bodyPanelInsets);
                ASwingHelper.prepare(this.m_bodyPanel);
            };
        }
        protected function updateFooterPanel():void{
        }
        protected function updateContentPanel():void{
            if (!this.m_content){
                this.m_content = this.createContentPlaceholder();
            };
            this.prepareContent();
            var _local1:AssetPane = new AssetPane(this.m_content);
            var _local2:Number = ((this.m_bodyPanel.getWidth() - this.m_content.width) / 2);
            ASwingHelper.setEasyBorder(_local1, 0, _local2);
            this.m_contentPanel.removeAll();
            this.m_contentPanel.append(_local1);
        }
        protected function createContentPlaceholder():DisplayObject{
            return (ASwingHelper.makeLabel(ZLoc.t("Dialogs", "Loading"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.darkBlueTextColor, JLabel.CENTER));
        }
        private function prepareContent():void{
            ASwingHelper.prepare(this);
            this.m_content.scaleX = (this.m_content.scaleY = this.scaleToFit(this.m_content));
            if ((this.m_content is Bitmap)){
                (this.m_content as Bitmap).smoothing = true;
            };
        }
        private function scaleToFit(_arg1:DisplayObject):Number{
            var _local2:Number = 1;
            var _local3:Number = 1;
            var _local4:int = this.m_bodyPanel.getHeight();
            var _local5:int = this.m_bodyPanel.getWidth();
            if (_arg1.width > _local5){
                _local2 = ((_local5 as Number) / _arg1.width);
            };
            if (_arg1.height > _local4){
                _local3 = ((_local4 as Number) / _arg1.height);
            };
            return (Math.min(_local2, _local3));
        }
        public function addEventListeners():void{
            addEventListener(MouseEvent.ROLL_OVER, this.onRollOver);
            addEventListener(MouseEvent.ROLL_OUT, this.onRollOut);
            addEventListener(MouseEvent.CLICK, this.onClick);
        }
        public function removeEventListeners():void{
            if (hasEventListener(MouseEvent.ROLL_OVER)){
                removeEventListener(MouseEvent.ROLL_OVER, this.onRollOver);
            };
            if (hasEventListener(MouseEvent.ROLL_OUT)){
                removeEventListener(MouseEvent.ROLL_OUT, this.onRollOut);
            };
            if (hasEventListener(MouseEvent.CLICK)){
                removeEventListener(MouseEvent.CLICK, this.onClick);
            };
        }
        protected function onRollOver(_arg1:MouseEvent=null):void{
        }
        protected function onRollOut(_arg1:MouseEvent=null):void{
        }
        protected function onClick(_arg1:MouseEvent=null):void{
        }

    }
}//package Display.GridlistUI.view 
